package org.omorphdb.core;

import java.io.IOException;
import java.util.List;

import org.omorphdb.core.classmap.ClassMap;
import org.omorphdb.core.storage.Statements;
import org.omorphdb.core.storage.document.Document;

/**
 * Session for an user accessing database functionality.
 */
public class Session
{
	private final Statements docFacade;
	private final ClassMap classMap;

	public class FilteredSet
	{
		private final Integer classID;
		private final String field;

		FilteredSet(Integer classID, String field)
		{
			this.classID = classID;
			this.field = field;
		}

		/**
		 * Returns documents matching the provided value.
		 * 
		 * @param value
		 * @return
		 * @throws IOException
		 */
		public List<Document> matches(Object value) throws IOException
		{
			return null;
		}
	}

	public class ClassSet
	{
		private final Class<?> cl;

		ClassSet(Class<?> cl)
		{
			this.cl = cl;
		}

		/**
		 * Initialize a query for a provided field.
		 * 
		 * @param field
		 * @return
		 */
		public FilteredSet where(String field)
		{
			int classID = Session.this.classMap.getId(cl.getCanonicalName());

			return new FilteredSet(classID, field);
		}
	}

	Session(Statements docFacade, ClassMap classMap)
	{
		this.docFacade = docFacade;
		this.classMap = classMap;
	}

	/**
	 * Returns an helper class providing methods to build a query.
	 * 
	 * @param cl A class of elements to be fetched.
	 * @return
	 */
	public ClassSet fetch(Class<?> cl)
	{
		return new ClassSet(cl);
	}
}
